//
//  ViewController.m
//  RPS
//
//  Created by iD Student on 7/8/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	turn1=true;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)rockButtonPressed:(id)sender
{
    if (turn1==true)
    {
        turn1=false;
        choice=1;
        turn.text=[NSString stringWithFormat:@"Player 2's turn"];
    }
    else
    {
        player2ImageView.image=[UIImage imageNamed:@"rock2.png"];
        turn1=true;
        turn.text=[NSString stringWithFormat:@"Player 1's turn"];
        if(choice==2)
        {
            win2+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"P2 wins"];
            player1ImageView.image = [UIImage imageNamed:@"scissors1.png"];
        }
        if(choice==3)
        {
            win1+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"P1 wins"];
            player1ImageView.image = [UIImage imageNamed:@"paper1.png"];
        }
        if(choice==1)
        {
            draw+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"Draw"];
            player1ImageView.image = [UIImage imageNamed:@"rock1.png"];
        }
    }
}

-(IBAction)scissorsButtonPressed:(id)sender
{
    if (turn1==true)
    {
        turn1=false;
        choice=2;
        turn.text=[NSString stringWithFormat:@"Player 2's turn"];
    }
    else
    {
        player2ImageView.image=[UIImage imageNamed:@"scissors2.png"];
        turn1=true;
        turn.text=[NSString stringWithFormat:@"Player 1's turn"];
        if(choice==3)
        {
            win2+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"P2 wins"];
            player1ImageView.image = [UIImage imageNamed:@"paper1.png"];
        }
        if(choice==1)
        {
            win1+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"P1 wins"];
            player1ImageView.image = [UIImage imageNamed:@"rock1.png"];
        }
        if(choice==2)
        {
            draw+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"Draw"];
            player1ImageView.image = [UIImage imageNamed:@"scissors1.png"];
        }
    }
}

-(IBAction)paperButtonPressed:(id)sender
{
    if (turn1==true)
    {
        turn1=false;
        choice=3;
        turn.text=[NSString stringWithFormat:@"Player 2's turn"];
    }
    else
    {
        player2ImageView.image=[UIImage imageNamed:@"paper2.png"];
        turn1=true;
        turn.text=[NSString stringWithFormat:@"Player 1's turn"];
        if(choice==1)
        {
            win2+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"P2 wins"];
            player1ImageView.image = [UIImage imageNamed:@"rock1.png"];
        }
        if(choice==2)
        {
            win1+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"P1 wins"];
            player1ImageView.image = [UIImage imageNamed:@"scissors1.png"];
        }
        if(choice==3)
        {
            draw+=1;
            record.text=[NSString stringWithFormat:@"%d/%d/%d", win1, draw, win2];
            victor.text=[NSString stringWithFormat:@"Draw"];
            player1ImageView.image = [UIImage imageNamed:@"paper1.png"];
        }
    }
}




@end
